<%@ taglib prefix="t" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<html>
<body>
<h2>User List</h2>
<script type="text/javascript">
	
	/*
	 * goto UserFormPage
	 */
	function goForm(id) {
		var f = document.forms[0];
		f.id.value = id;
		f.mode.value = 'goForm';
		f.action = "userFormPage";
		f.submit();
	}
	
	function doDelete() {
		var checkId = document.getElementsByName("checkId");
		var f = document.forms[0];
		f.action = "deleteUsers";

		for (var i = 0; i < checkId.length; i++) {
			if (checkId[i].checked) {
				//alert(checkId[i].value);
				f.submit();
			}
		}
	}

</script>
<div>
     <form id="form1" action="userLogin" method="post">
     	<input type="hidden" id="id" name="id" value=""/>
     	<input type="hidden" id="mode" name="mode" value=""/>
	    <input type="hidden" id="message" value="${message}"/>
	    <input type="hidden" id="from_mode" value="${from_mode}"/>
	    
		<table border="1" style="width:300px;">
			<c:forEach var="person" items="${persons}">
				<tr>
					<td>
						<input type="checkbox" name="checkId" value="${person.id}" />
					</td>
					<td>
						<a href="javascript:goForm('<c:out value="${person.id}"/>')">
							<c:out value="${person.id}"/>
						</a>
					</td>
					<td>
						<c:out value="${person.name}"/>
					</td>
					<td>
						<c:out value="${person.age}"/>
					</td>
					<td>
						<c:out value="${person.sex}"/>
					</td>
					<td>
						<c:out value="${person.city}"/>
					</td>
				</tr>
			</c:forEach>
		</table>
		
		<input name="btn" type="button" value="Delete Checked User"  onclick="doDelete()"/>
	<!--<fmt:formatDate value="${today}"/> 	
	    <input name="loginName" type="text" value="" />
		<input name="btn" type="button" value="User Login"  onclick="form1.submit();"/> -->
	</form>
</div>
</body>
<script type="text/javascript">
	function onLoad() {
		
		var f = document.forms[0];
		var msg = f.message.value;
		 
		//var from_mode = form1.from_mode.value; 
		//alert(from_mode);
		
		//deleteUsers
		if (msg != '') {
			alert(msg);
		}
	}
	window.onload = onLoad();
</script>
	<a href="userLogin">User Login Page</a><br>
	<a href="addUserPage">Add User Page</a><br>
	<a href="userList">User List Page</a><br>
	<a href="javascript:history.back()">Back</a>
</html>
